<!doctype html>
<html class="default no-js">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>Controller | hap-nodejs</title>
	<meta name="description" content="Documentation for hap-nodejs">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="../assets/css/main.css">
	<script async src="../assets/js/search.js" id="search-script"></script>
</head>
<body>
<header>
	<div class="tsd-page-toolbar">
		<div class="container">
			<div class="table-wrap">
				<div class="table-cell" id="tsd-search" data-index="../assets/js/search.json" data-base="..">
					<div class="field">
						<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
						<input id="tsd-search-field" type="text" />
					</div>
					<ul class="results">
						<li class="state loading">Preparing search index...</li>
						<li class="state failure">The search index is not available</li>
					</ul>
					<a href="../index.html" class="title">hap-nodejs</a>
				</div>
				<div class="table-cell" id="tsd-widgets">
					<div id="tsd-filter">
						<a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
						<div class="tsd-filter-group">
							<div class="tsd-select" id="tsd-filter-visibility">
								<span class="tsd-select-label">All</span>
								<ul class="tsd-select-list">
									<li data-value="public">Public</li>
									<li data-value="protected">Public/Protected</li>
									<li data-value="private" class="selected">All</li>
								</ul>
							</div>
							<input type="checkbox" id="tsd-filter-inherited" checked />
							<label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
						</div>
					</div>
					<a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
				</div>
			</div>
		</div>
	</div>
	<div class="tsd-page-title">
		<div class="container">
			<ul class="tsd-breadcrumb">
				<li>
					<a href="../modules.html">hap-nodejs</a>
				</li>
				<li>
					<a href="controller.html">Controller</a>
				</li>
			</ul>
			<h1>Interface Controller&lt;M&gt;</h1>
		</div>
	</div>
</header>
<div class="container container-main">
	<div class="row">
		<div class="col-8 col-content">
			<section class="tsd-panel tsd-comment">
				<div class="tsd-comment tsd-typography">
					<div class="lead">
						<p>A Controller represents a somewhat more complex arrangement of multiple services which together form a accessory
							like for example cameras, remotes, tvs or routers.
							Controllers implementing this interface are capable of being serialized and thus stored on and recreated from disk.
							Meaning services, characteristic configurations and optionally additional controller states can be persistently saved.
							As a result, implementors of this interface need to follow strict guidelines on how to initialize their
						services and characteristics.</p>
					</div>
					<p>The set of services can change though over the lifespan of the implementation (e.g. protocol changes imposed by HAP like
						the addition of secure-video for cameras).
					Such changes can be made using <a href="controller.html#initwithservices">initWithServices</a>. See below for more infos.</p>
					<p>The constructor of a Controller should only initialize controller specific configuration and states
						and MUST NOT create any services or characteristics.
						Additionally it must implement all necessary methods as noted below. Those methods will get called
					when the accessory gets added to an Accessory or a Accessory is restored from disk.</p>
				</div>
			</section>
			<section class="tsd-panel tsd-type-parameters">
				<h3>Type parameters</h3>
				<ul class="tsd-type-parameters">
					<li>
						<h4>M<span class="tsd-signature-symbol">: </span><a href="controllerservicemap.html" class="tsd-signature-type" data-tsd-kind="Interface">ControllerServiceMap</a> = <a href="controllerservicemap.html" class="tsd-signature-type" data-tsd-kind="Interface">ControllerServiceMap</a></h4>
					</li>
				</ul>
			</section>
			<section class="tsd-panel tsd-hierarchy">
				<h3>Hierarchy</h3>
				<ul class="tsd-hierarchy">
					<li>
						<span class="target">Controller</span>
						<ul class="tsd-hierarchy">
							<li>
								<a href="serializablecontroller.html" class="tsd-signature-type" data-tsd-kind="Interface">SerializableController</a>
							</li>
						</ul>
					</li>
				</ul>
			</section>
			<section class="tsd-panel">
				<h3>Implemented by</h3>
				<ul class="tsd-hierarchy">
					<li><a href="../classes/cameracontroller.html" class="tsd-signature-type" data-tsd-kind="Class">CameraController</a></li>
				</ul>
			</section>
			<section class="tsd-panel-group tsd-index-group">
				<h2>Index</h2>
				<section class="tsd-panel tsd-index-panel">
					<div class="tsd-index-content">
						<section class="tsd-index-section ">
							<h3>Methods</h3>
							<ul class="tsd-index-list">
								<li class="tsd-kind-method tsd-parent-kind-interface"><a href="controller.html#configureservices" class="tsd-kind-icon">configure<wbr>Services</a></li>
								<li class="tsd-kind-method tsd-parent-kind-interface"><a href="controller.html#constructservices" class="tsd-kind-icon">construct<wbr>Services</a></li>
								<li class="tsd-kind-method tsd-parent-kind-interface"><a href="controller.html#controllerid" class="tsd-kind-icon">controller<wbr>Id</a></li>
								<li class="tsd-kind-method tsd-parent-kind-interface"><a href="controller.html#handlecontrollerremoved" class="tsd-kind-icon">handle<wbr>Controller<wbr>Removed</a></li>
								<li class="tsd-kind-method tsd-parent-kind-interface"><a href="controller.html#handlefactoryreset" class="tsd-kind-icon">handle<wbr>Factory<wbr>Reset</a></li>
								<li class="tsd-kind-method tsd-parent-kind-interface"><a href="controller.html#initwithservices" class="tsd-kind-icon">init<wbr>With<wbr>Services</a></li>
							</ul>
						</section>
					</div>
				</section>
			</section>
			<section class="tsd-panel-group tsd-member-group ">
				<h2>Methods</h2>
				<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface">
					<a name="configureservices" class="tsd-anchor"></a>
					<h3>configure<wbr>Services</h3>
					<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface">
						<li class="tsd-signature tsd-kind-icon">configure<wbr>Services<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li>
					</ul>
					<ul class="tsd-descriptions">
						<li class="tsd-description">
							<aside class="tsd-sources">
								<ul>
									<li>Defined in <a href="https://github.com/homebridge/HAP-NodeJS/blob/95a2490/src/lib/controller/Controller.ts#L105">lib/controller/Controller.ts:105</a></li>
								</ul>
							</aside>
							<div class="tsd-comment tsd-typography">
								<div class="lead">
									<p>This method is called to configure the services and their characteristics of the controller.
										When this method is called, it is guaranteed that either <a href="controller.html#constructservices">constructServices</a> or <a href="controller.html#initwithservices">initWithServices</a>
									were called before and all services are already created.</p>
								</div>
								<p>This method SHOULD set up all necessary event handlers for services and characteristics.</p>
							</div>
							<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
						</li>
					</ul>
				</section>
				<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface">
					<a name="constructservices" class="tsd-anchor"></a>
					<h3>construct<wbr>Services</h3>
					<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface">
						<li class="tsd-signature tsd-kind-icon">construct<wbr>Services<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">M</span></li>
					</ul>
					<ul class="tsd-descriptions">
						<li class="tsd-description">
							<aside class="tsd-sources">
								<ul>
									<li>Defined in <a href="https://github.com/homebridge/HAP-NodeJS/blob/95a2490/src/lib/controller/Controller.ts#L82">lib/controller/Controller.ts:82</a></li>
								</ul>
							</aside>
							<div class="tsd-comment tsd-typography">
								<div class="lead">
									<p>This method is called by the accessory the controller is added to. This method is only called if a new controller
										is constructed (aka the controller is not restored from disk {@see initWithServices}).
										It MUST create all needed services and characteristics.
										It MAY create links between services or mark them as hidden or primary.
										It MUST NOT configure any event handlers.
									The controller SHOULD save created services in internal properties for later access.</p>
								</div>
								<p>The method must return all created services in a ServiceMap.
									A <a href="controllerservicemap.html">ControllerServiceMap</a> basically maps a name to every service on the controller.
								It is used to potentially recreate a controller for a given ServiceMap using <a href="controller.html#initwithservices">initWithServices</a>.</p>
								<p>The set of services represented by the Controller MUST remain static and can only change over new version of
								the Controller implementation (see <a href="controller.html#initwithservices">initWithServices</a>)</p>
							</div>
							<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">M</span></h4>
							<p>a <a href="controllerservicemap.html">ControllerServiceMap</a> representing all services of a controller indexed by a controller chosen name.</p>
						</li>
					</ul>
				</section>
				<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface">
					<a name="controllerid" class="tsd-anchor"></a>
					<h3>controller<wbr>Id</h3>
					<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface">
						<li class="tsd-signature tsd-kind-icon">controller<wbr>Id<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span></li>
					</ul>
					<ul class="tsd-descriptions">
						<li class="tsd-description">
							<aside class="tsd-sources">
								<ul>
									<li>Defined in <a href="https://github.com/homebridge/HAP-NodeJS/blob/95a2490/src/lib/controller/Controller.ts#L63">lib/controller/Controller.ts:63</a></li>
								</ul>
							</aside>
							<div class="tsd-comment tsd-typography">
								<div class="lead">
									<p>Every instance of a Controller must define appropriate identifying material.
									The returned identifier MUST NOT change over the lifetime of the Controller object.</p>
								</div>
								<p>Note: The controller can choose to return the same identifier for all controllers of the same type.
								This will result in the user only being able to add ONE instance of an Controller to an accessory.</p>
								<p>Some predefined identifiers can be found in <a href="../modules.html#controlleridentifier">ControllerIdentifier</a>.</p>
							</div>
							<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">string</span></h4>
						</li>
					</ul>
				</section>
				<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface">
					<a name="handlecontrollerremoved" class="tsd-anchor"></a>
					<h3>handle<wbr>Controller<wbr>Removed</h3>
					<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface">
						<li class="tsd-signature tsd-kind-icon">handle<wbr>Controller<wbr>Removed<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li>
					</ul>
					<ul class="tsd-descriptions">
						<li class="tsd-description">
							<aside class="tsd-sources">
								<ul>
									<li>Defined in <a href="https://github.com/homebridge/HAP-NodeJS/blob/95a2490/src/lib/controller/Controller.ts#L118">lib/controller/Controller.ts:118</a></li>
								</ul>
							</aside>
							<div class="tsd-comment tsd-typography">
								<div class="lead">
									<p>This method is called once the Controller is removed from the accessory.
										The controller MUST reset everything to its initial state (just as it would have been constructed freshly)
										form the constructor.
										Adding the Controller back to an accessory after it was removed MUST be supported!
										If the controller is a <a href="serializablecontroller.html">SerializableController</a> it MUST NOT call the <a href="../modules.html#statechangedelegate">StateChangeDelegate</a>
									as a result of a call to this method.</p>
								</div>
								<p>All service contained in the <a href="controllerservicemap.html">ControllerServiceMap</a> returned by <a href="controller.html#constructservices">constructServices</a>
								will be automatically removed from the Accessory. The Controller MUST remove any references to those services.</p>
							</div>
							<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
						</li>
					</ul>
				</section>
				<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface">
					<a name="handlefactoryreset" class="tsd-anchor"></a>
					<h3><span class="tsd-flag ts-flagOptional">Optional</span> handle<wbr>Factory<wbr>Reset</h3>
					<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface">
						<li class="tsd-signature tsd-kind-icon">handle<wbr>Factory<wbr>Reset<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li>
					</ul>
					<ul class="tsd-descriptions">
						<li class="tsd-description">
							<aside class="tsd-sources">
								<ul>
									<li>Defined in <a href="https://github.com/homebridge/HAP-NodeJS/blob/95a2490/src/lib/controller/Controller.ts#L126">lib/controller/Controller.ts:126</a></li>
								</ul>
							</aside>
							<div class="tsd-comment tsd-typography">
								<div class="lead">
									<p>This method is called to signal a factory reset of the controller and its services and characteristics.
									A controller MUST reset any configuration or states to default values.</p>
								</div>
								<p>This method is called once the accessory gets unpaired or the Controller gets removed from the Accessory.</p>
							</div>
							<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
						</li>
					</ul>
				</section>
				<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface">
					<a name="initwithservices" class="tsd-anchor"></a>
					<h3>init<wbr>With<wbr>Services</h3>
					<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface">
						<li class="tsd-signature tsd-kind-icon">init<wbr>With<wbr>Services<span class="tsd-signature-symbol">(</span>serviceMap<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">M</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">M</span></li>
					</ul>
					<ul class="tsd-descriptions">
						<li class="tsd-description">
							<aside class="tsd-sources">
								<ul>
									<li>Defined in <a href="https://github.com/homebridge/HAP-NodeJS/blob/95a2490/src/lib/controller/Controller.ts#L96">lib/controller/Controller.ts:96</a></li>
								</ul>
							</aside>
							<div class="tsd-comment tsd-typography">
								<div class="lead">
									<p>This method is called to initialize the controller with already created services.
									The controller SHOULD save the passed services in internal properties for later access.</p>
								</div>
								<p>The controller can return a ServiceMap to signal that the set of services changed.
									A Controller MUST modify the ServiceMap which is passed to the method and MUST NOT create a new one (to support inheritance).
									It MUST NOT return a ServiceMap if the service configuration did not change!
								It MUST be able to restore services using a ServiceMap from any point in time.</p>
							</div>
							<h4 class="tsd-parameters-title">Parameters</h4>
							<ul class="tsd-parameters">
								<li>
									<h5>serviceMap: <span class="tsd-signature-type">M</span></h5>
									<div class="tsd-comment tsd-typography">
										<p>represents all services of a controller indexed by the controller chosen name.</p>
									</div>
								</li>
							</ul>
							<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">M</span></h4>
							<p>optionally a {ControllerServiceMap}. This can be used to alter the services configuration of a controller.</p>
						</li>
					</ul>
				</section>
			</section>
		</div>
		<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
			<nav class="tsd-navigation primary">
				<ul>
					<li class=" ">
						<a href="../modules.html">Exports</a>
					</li>
				</ul>
			</nav>
			<nav class="tsd-navigation secondary menu-sticky">
				<ul class="before-current">
				</ul>
				<ul class="current">
					<li class="current tsd-kind-interface tsd-has-type-parameter">
						<a href="controller.html" class="tsd-kind-icon">Controller</a>
						<ul>
							<li class=" tsd-kind-method tsd-parent-kind-interface">
								<a href="controller.html#configureservices" class="tsd-kind-icon">configure<wbr>Services</a>
							</li>
							<li class=" tsd-kind-method tsd-parent-kind-interface">
								<a href="controller.html#constructservices" class="tsd-kind-icon">construct<wbr>Services</a>
							</li>
							<li class=" tsd-kind-method tsd-parent-kind-interface">
								<a href="controller.html#controllerid" class="tsd-kind-icon">controller<wbr>Id</a>
							</li>
							<li class=" tsd-kind-method tsd-parent-kind-interface">
								<a href="controller.html#handlecontrollerremoved" class="tsd-kind-icon">handle<wbr>Controller<wbr>Removed</a>
							</li>
							<li class=" tsd-kind-method tsd-parent-kind-interface">
								<a href="controller.html#handlefactoryreset" class="tsd-kind-icon">handle<wbr>Factory<wbr>Reset</a>
							</li>
							<li class=" tsd-kind-method tsd-parent-kind-interface">
								<a href="controller.html#initwithservices" class="tsd-kind-icon">init<wbr>With<wbr>Services</a>
							</li>
						</ul>
					</li>
				</ul>
				<ul class="after-current">
				</ul>
			</nav>
		</div>
	</div>
</div>
<footer>
	<div class="container">
		<h2>Legend</h2>
		<div class="tsd-legend-group">
			<ul class="tsd-legend">
				<li class="tsd-kind-constructor tsd-parent-kind-interface"><span class="tsd-kind-icon">Constructor</span></li>
				<li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li>
				<li class="tsd-kind-method tsd-parent-kind-interface"><span class="tsd-kind-icon">Method</span></li>
			</ul>
			<ul class="tsd-legend">
				<li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li>
				<li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li>
				<li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li>
			</ul>
			<ul class="tsd-legend">
				<li class="tsd-kind-constructor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited constructor</span></li>
				<li class="tsd-kind-property tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited property</span></li>
				<li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited method</span></li>
			</ul>
			<ul class="tsd-legend">
				<li class="tsd-kind-property tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static property</span></li>
				<li class="tsd-kind-method tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li>
			</ul>
		</div>
	</div>
</footer>
<div class="overlay"></div>
<script src="../assets/js/main.js"></script>
</body>
</html>